package com.starblink.feedback

import android.view.View
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.starblink.android.basic.adapter.MutableAdapter
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.ext.inflater
import com.starblink.android.basic.extension.dp2px
import com.starblink.android.basic.extension.lazyOnNone
import com.starblink.android.basic.widget.dialog.BaseBottomSheetFragment
import com.starblink.feedback.adapter.PostProductHolder
import com.starblink.feedback.databinding.ItemPostProductBinding
import com.starblink.feedback.databinding.ProductDialogLayoutBinding
import com.starblink.rocketreserver.fragment.ProductF

class PostProductDialog(val cont: FragmentActivity, val postId: String, val list: ArrayList<ProductF>) :
    BaseBottomSheetFragment() {
    lateinit var mBinding: ProductDialogLayoutBinding
    override fun getBindingRootView(): View {
        mBinding = ProductDialogLayoutBinding.inflate(layoutInflater)
        return mBinding.root
    }

    private val adapter: MutableAdapter by lazyOnNone {
        MutableAdapter(list).apply {
            addVhDelegate {
                PostProductHolder(
                    ItemPostProductBinding.inflate(it.inflater, it, false), cont
                )
            }
        }
    }

    override fun initView() {
        var height = 104 * list.size + 56 + 20
        setPeekHeight(height.dp2px())
        mBinding.close.click {
            dismiss()
        }

        mBinding.recyclerView.layoutManager = LinearLayoutManager(cont)
        mBinding.recyclerView.setHasFixedSize(true)
        mBinding.recyclerView.itemAnimator = null
        mBinding.recyclerView.adapter = adapter//单位px

//        CoroutineScope(Dispatchers.IO).launch {
//            val response = SkGqlClient.skQuery(
//                FetchPostsQuery(
//                    postParams = PostRecommendQueryParam(
//                        1,
//                        relatedPostId = Optional.present(""),
//                        PostConfig.postRecommendPage,
//                        12,
//                        advertiseId = Optional.present(""),
//                        clientTime = Optional.present(System.currentTimeMillis().toString()),
//                        isReported = Optional.present(false),
//                    ),  false, isPostDetail = false
//                )
//
//            )
//
//            if (response?.data != null && response.data!!.fetchRecommendPost != null) {
//                var list1 = response.data!!.fetchRecommendPost
//                MainScope().launch {
//                }
//            }
//        }
    }
}